#define GETTEXT_DOMAIN "wesnoth-lib"

#include "gui/dialogs/addon_list.hpp"

#include "foreach.hpp"
#ifdef GUI2_EXPERIMENTAL_LISTBOX
#include "gui/widgets/list.hpp"
#else
#include "gui/widgets/listbox.hpp"
#endif
#include "gui/widgets/settings.hpp"
#include "gui/widgets/window.hpp"

namespace gui2
{
	REGISTER_WINDOW(addon_list)
	
	void taddon_list::pre_show(CVideo&, twindow& window)
	{
		tlistbox& list = find_widget<tlistbox>(&window, "addons", false);
		
		foreach(const config& c, cfg_.child_range("campaign"))
		{
			std::map<std::string, string_map> data;
			string_map item;
			
			std::string tmp = c["name"];
			utils::truncate_as_wstring(tmp, 20);
			item["label"] = tmp;
			data.insert(std::make_pair("name", item));
			
			tmp = c["version"].str();
			utils::truncate_as_wstring(tmp, 20);
			item["label"] = tmp;
			data.insert(std::make_pair("version", item));
			
			tmp = c["author"].str();
			utils::truncate_as_wstring(tmp, 16);
			item["label"] = tmp;
			data.insert(std::make_pair("author", item));
			
			item["label"] = c["downloads"];
			data.insert(std::make_pair("downloads", item));
			
			item["label"] = c["size"];
			data.insert(std::make_pair("size", item));
			
			list.add_row(data);
		}
	}
}
